<template>
  <el-dropdown @command="changeLang">
    <span class="el-dropdown-link">
      <svg-icon class="lang" icon-class="language" />
    </span>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh">中文</el-dropdown-item>
      <el-dropdown-item command="en">English</el-dropdown-item>
      <el-dropdown-item command="ja">日本語</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>

// 导入操作cookie的库
import Cookies from 'js-cookie'

export default {

    methods: {

        changeLang (cmd) {

            // 我要切换语言
            this.$i18n.locale = cmd
            // element-ui的界面部分要刷新才会跟着变
            // 把本次选择的语言保存起来
            // localStorage.setItem('lang', cmd)
            
            // 失效时间以天为单位，所以现在代表7天后失效
            Cookies.set('lang', cmd, { expires: 7 })
            // 就地刷新
            this.$router.go(0)
        }
    }
}
</script>

<style scoped>
.lang {
    font-size: 22px;
    margin-right: 10px;
    color:#fff;
}
</style>